<?php

include_once "function_xml_basic.php";

$root_path = "/MINI/SECURITY/DISABLE";

function GetXmlAbleServerInfoList()
{
	global $root_path;
	$query_string = $root_path. "/CONFIG";
        $key_array = array("Enabled", "MSN","QQ", "AIM","JABBER","IRC","YAHOO","BT","EMAULE","XUNLEI","STREAM");
        return GetAttributList($query_string, $key_array);
}
/*
$ret_array = GetXmlAbleServerInfoList();
foreach ($ret_array as $i)
{
	print $i["MSN"];
	print $i["QQ"];
}
*/
function SetXmlAbleServerInfo($in_array)
{
        global $root_path;
        $query_string = $root_path. "/CONFIG[1]";

        EditAllAttrOfNode($query_string, $in_array);

	ApplySysAbleConfig();
}

function FlushSysAbleConfig()
{
	$command = "/usr/local/bin/iptables -t nat -F DISABLED ;";
	//print $command;
	$ret = shell_exec($command);
	return $ret;
}

function ApplySysAbleConfig()
{
	FlushSysAbleConfig();
	
	ApplySysAbleConfig_One();
}
function ApplySysAbleConfig_One()
{
	$iptables = "/usr/local/bin/iptables -t nat -A DISABLED -m layer7 --l7proto ";
	$active = " -j DROP ; ";
	
	$ret_array = GetXmlAbleServerInfoList();
	$ret = $ret_array[0];
	
	if ($ret['Enabled'] == 0) 
	{
		return ;
	}
	
	$command = ""; 
	if ($ret["MSN"] == 1)
	{
		$command_msn = $iptables. " msnmessenger ". $active;
		$command_msnfile = $iptables. " msn-filetransfer ". $active;
		$command .= $command_msn. $command_msnfile;
	}
	if ($ret["QQ"] == 1)
	{
		$command_qq = $iptables. " qq ". $active;
		$command .= $command_qq;
	}
	if ($ret["AIM"] == 1)
	{
		$command_aim = $iptables. " aim  ". $active;
		$command_aimweb = $iptables. " aimwebcontent ". $active;
		$command .= $command_aim. $command_aimweb;
	}

	if ($ret["JABBER"] == 1)
	{
		$command_jabber = $iptables. " jabber ". $active;
		$command .= $command_jabber;
	}
	if ($ret["IRC"] == 1)
	{
		$command_irc = $iptables. " irc ". $active;
		$command .= $command_irc;
	}
	if ($ret["YAHOO"] == 1)
	{
		$command_yahoo = $iptables. " yahoo ". $active;
		$command .= $command_yahoo;
	}
	if ($ret["BT"] == 1)
	{
		$command_bittorrent = $iptables. " bittorrent ". $active;
		$command .= $command_bittorrent;
	}
	if ($ret["EMAULE"] == 1)
	{
		$command_tmp = "";
		$command_tmp = $iptables. " edonkey ". $active;
		$command .= $command_tmp;
	}
	if ($ret["XUNLEI"] == 1)
	{
		$command_tmp = "";
		$command_tmp = $iptables. " xunlei ". $active;
		$command .= $command_tmp;
	}
	if ($ret["STREAM"] == 1)
	{
		$command_tmp = "";
		$command_tmp = $iptables. " http-rtsp ". $active;
		$command .= $command_tmp;
		
		$command_tmp = "";
		$command_tmp = $iptables. " live365 ". $active;
		$command .= $command_tmp;

		$command_tmp = "";
		$command_tmp = $iptables. " rtp ". $active;
		$command .= $command_tmp;
		
		$command_tmp = "";
		$command_tmp = $iptables. " rtsp ". $active;
		$command .= $command_tmp;
	}
	//print $command;
	$ret = shell_exec ($command);
	return $ret;
}

?>
